package org.example.coffeeshoporderingsystem.report.controller;

import javafx.fxml.FXML;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.PieChart;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import org.example.coffeeshoporderingsystem.common.controller.BaseController;

import java.net.URL;
import java.util.ResourceBundle;

public class ReportController extends BaseController {

    @FXML
    private BarChart<String, Number> barChart;

    @FXML
    private CategoryAxis xAxis;

    @FXML
    private NumberAxis yAxis;

    @FXML
    private LineChart<String, Number> lineChart;

    @FXML
    private CategoryAxis lineXAxis;

    @FXML
    private NumberAxis lineYAxis;

    @FXML
    private PieChart pieChart;


    @FXML
    public void initialize() {
        // 设置 X 轴和 Y 轴的标签
        xAxis.setLabel("月份");
        yAxis.setLabel("收入");

        // 创建柱状图数据系列
        XYChart.Series<String, Number> barSeries = new XYChart.Series<>();
        barSeries.setName("月收入");

        // 添加数据点
        barSeries.getData().add(new XYChart.Data<>("一月", 1000));
        barSeries.getData().add(new XYChart.Data<>("二月", 1500));
        barSeries.getData().add(new XYChart.Data<>("三月", 1200));
        barSeries.getData().add(new XYChart.Data<>("四月", 1800));
        barSeries.getData().add(new XYChart.Data<>("五月", 2000));

        // 将数据系列添加到柱状图
        barChart.getData().add(barSeries);

        // 创建折线图数据系列
        /*XYChart.Series<String, Number> lineSeries = new XYChart.Series<>();
        lineSeries.setName("月收入");

        // 添加数据点
        lineSeries.getData().add(new XYChart.Data<>("一月", 1000));
        lineSeries.getData().add(new XYChart.Data<>("二月", 1500));
        lineSeries.getData().add(new XYChart.Data<>("三月", 1200));
        lineSeries.getData().add(new XYChart.Data<>("四月", 1800));
        lineSeries.getData().add(new XYChart.Data<>("五月", 2000));

        // 将数据系列添加到折线图
        lineChart.getData().add(lineSeries);*/

        /*// 创建饼图数据系列
        pieChart.getData().addAll(
            new PieChart.Data("一月", 1000),
            new PieChart.Data("二月", 1500),
            new PieChart.Data("三月", 1200),
            new PieChart.Data("四月", 1800),
            new PieChart.Data("五月", 2000)
        );

        // 默认显示柱状图
        showBarChart();*/
    }

    @FXML
    private void handleLineChartButtonAction() {
        showLineChart();
    }

    @FXML
    private void handlePieChartButtonAction() {
        showPieChart();
    }

    @FXML
    private void handleBarChartButtonAction() {
        showBarChart();
    }

    private void showBarChart() {
        barChart.setVisible(true);
        lineChart.setVisible(false);
        pieChart.setVisible(false);
        // 隐藏其他图表类型
    }

    private void showLineChart() {
        barChart.setVisible(false);
        lineChart.setVisible(true);
        pieChart.setVisible(false);
        // 隐藏其他图表类型
    }

    private void showPieChart() {
        barChart.setVisible(false);
        lineChart.setVisible(false);
        pieChart.setVisible(true);
        // 隐藏其他图表类型
    }

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {
        this.initialize();
    }
}
